from pydantic import BaseModel, Field
from typing import Optional
{% set DECIMAL_TYPES = ['DECIMAL', 'NUMERIC', 'MONEY', 'NUMMULTIRANGE', 'NUMRANGE'] %}
{% set DATETIME_TYPES = ['DATETIME', 'TIMESTAMP', 'TIMESTAMPTZ'] %}
{% set DATE_TYPES = ['DATE'] %}

{% if model_types|select('in', DECIMAL_TYPES)|first %}
from decimal import Decimal
{% endif %}
{% if model_types|select('in', DATETIME_TYPES)|first %}
from datetime import datetime
{% endif %}
{% if model_types|select('in', DATE_TYPES)|first %}
from datetime import date
{% endif %}
{% if 'Uuid' in model_types or 'UUID' in model_types %}
from uuid import UUID
{% endif %}


class {{ class_name }}Base(BaseModel):
{% for col in models %}
{% if col.is_pk %}
{# 排除主键字段，不作为输入 #}
{% elif not col.is_nullable and not col.default %}
    {{ col.name }}: {{ col.pd_type }} = Field(..., description="{{ col.comment or '' }}")
{% else %}
    {{ col.name }}: Optional[{{ col.pd_type }}] = Field(None, description="{{ col.comment or '' }}")
{% endif %}
{% endfor %}


class {{ class_name }}Create({{ class_name }}Base):
    pass


class {{ class_name }}Update(BaseModel):
{% for col in models %}
{% if not col.is_pk %}
    {{ col.name }}: Optional[{{ col.pd_type }}] = Field(None, description="{{ col.comment or '' }}")
{% endif %}
{% endfor %}